package com.shop2cn.iapi.agentproducts.testcase;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.AgentPriceDto;
import com.shop2cn.iapi.agentproducts.parameter.GetProductListBean;
import com.shop2cn.iapi.agentproducts.parameter.ImportAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductListDto;
import com.shop2cn.iapi.agentproducts.parameter.UpdateAgentTypeBean;
import com.shop2cn.iapi.agentproducts.service.UpdateAgentTypeCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.notify.parameter.GetMessageListByTimelineNewBean;
import com.ymatou.iapi.notify.parameter.NotifyResModelDto;
import com.ymatou.iapi.notify.parameter.emu.MessageIsNew;
import com.ymatou.iapi.notify.service.GetMessageListByTimelineNewCall;
import com.ymatou.iapi.prodstock.parameter.AgentProductPo;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.YmtProductsI;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.YMTDateUtil;

/**
*更新代理级别（商户后台调用）
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UpdateAgentType{
	private static UpdateAgentTypeBean updateagenttypeBean;
	private static UpdateAgentTypeCall updateagenttypeCall;
	private static YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();

	//vip渠道
	private static int vipRootUserId = AgentUsers.vipRootUserId;
	private static String vipRootUserName = "NickautoTest";
	//vip渠道->代理
	private static int vipAgentUserId1 = AgentUsers.vipAgentUserId1;
	private static String vipAgentUserName1 = "dgsq408897016";
	//vip渠道->代理->代理
	private static int vipAgentUserId2 = AgentUsers.vipAgentUserId2;
	private static String vipAgentUserName2 = "NickautoTest";

	//渠道商
	private static int sellerId = AgentUsers.rootUserId;
	private static String sellerName = "NickautoTest";
	//渠道商->代理商1
	private static int agentUserId1 = AgentUsers.agentUserId1;
	private static String agentUserName1 = "NickautoTest";
	//渠道商->代理商2
	private static int agentUserId2 = AgentUsers.agentUserId2;
	private static String agentUserName2 = "NickautoTest";
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新代理级别（商户后台调用）");
	}

	@Before
	public void caseUp() {
		updateagenttypeBean=new UpdateAgentTypeBean();
		updateagenttypeCall=new UpdateAgentTypeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updateagenttypeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateAgentType_01() {
		Logger.start(true,"vip渠道->vip1->vip2,多规格商品，渠道商修改下级代理商代理类型，修改后所有规格（代理价>下级代理商直销价），发送通知");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,vipRootUserName,true);
			addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).setAgentPrice(300);
			addAgentProductBean.getCatalogList().get(1).getAgentPriceList().get(1).setAgentPrice(300);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId1,vipAgentUserName1,productId,vipRootUserId,true);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);
			//vip代理2
			ImportAgentProductBean importAgentProductBean1 = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId2,vipAgentUserName2,agentProductId,vipAgentUserId1,false);
			String agentProductId1 = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean1);

			updateagenttypeBean.setUserId(vipRootUserId);
			updateagenttypeBean.setAgentTypeId(146);
			updateagenttypeBean.setUpdatedUserId(vipAgentUserId1);
			updateagenttypeCall.setData(updateagenttypeBean);
			updateagenttypeCall.callService();

			Thread.sleep(2000);
			Logger.verifyEquals("200",updateagenttypeCall.getString("code"),"验证code");
			List<NotifyResModelDto> notify = getNotify(vipAgentUserId1);
			Logger.verifyEquals(true,notify.get(0).getMessage().contains(importAgentProductBean.getTitle()),"验证发送通知成功");

			//验证vip1
			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
			Logger.verifyEquals(-2,agentProductPo.getInfoProgress(),"验证InfoProgress");
			Logger.verifyEquals(0,agentProductPo.getAction(),"验证action");

			//同步服务会将action改成-2  时间延迟
			AgentProductPo agentProductPo1 = ymtProductsIWapper.selectAgentProductByProductId(agentProductId1);
			Logger.verifyEquals(-2,agentProductPo1.getAction(),"验证action");
			Logger.verifyEquals(0,agentProductPo1.getInfoProgress(),"验证action");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

    @Test
    @Category({P1.class})
    @TestCase
    public void Tc_UpdateAgentType_11() {
        Logger.start(true,"vip渠道->vip1->vip2,多规格商品，渠道商修改下级代理商代理类型，修改后其中一个规格（代理价>下级代理商直销价），发送通知");
        try {
            //vip渠道
            AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,vipRootUserName,true);
            addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).setAgentPrice(300);
            String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
            //vip代理1
            ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId1,vipAgentUserName1,productId,vipRootUserId,true);
            String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);
            //vip代理2
            ImportAgentProductBean importAgentProductBean1 = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId2,vipAgentUserName2,agentProductId,vipAgentUserId1,false);
            String agentProductId1 = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean1);

            updateagenttypeBean.setUserId(vipRootUserId);
            updateagenttypeBean.setAgentTypeId(146);
            updateagenttypeBean.setUpdatedUserId(vipAgentUserId1);
            updateagenttypeCall.setData(updateagenttypeBean);
            updateagenttypeCall.callService();

            Thread.sleep(5000);
            Logger.verifyEquals("200",updateagenttypeCall.getString("code"),"验证code");
            List<NotifyResModelDto> notify = getNotify(vipAgentUserId1);
            Logger.verifyEquals(true,notify.get(0).getMessage().contains(importAgentProductBean.getTitle()),"验证发送通知成功");

            //验证vip1
            AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
            Logger.verifyEquals(-2,agentProductPo.getInfoProgress(),"验证InfoProgress");
            Logger.verifyEquals(0,agentProductPo.getAction(),"验证action");

            //同步服务会将action改成-2  时间延迟
            AgentProductPo agentProductPo1 = ymtProductsIWapper.selectAgentProductByProductId(agentProductId1);
            Logger.verifyEquals(-2,agentProductPo1.getAction(),"验证action");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateAgentType_08() {
		Logger.start(true,"vip渠道->vip1->vip2,渠道商修改下级代理商代理类型，修改后（代理价<下级代理商直销价）,不发送通知");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,vipRootUserName,true);
			addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).setAgentPrice(100);
			addAgentProductBean.getCatalogList().get(1).getAgentPriceList().get(1).setAgentPrice(100);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId1,vipAgentUserName1,productId,vipRootUserId,true);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);
			//vip代理2
			ImportAgentProductBean importAgentProductBean1 = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId2,vipAgentUserName2,agentProductId,vipAgentUserId1,false);
			String agentProductId1 = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean1);

			updateagenttypeBean.setUserId(vipRootUserId);
			updateagenttypeBean.setAgentTypeId(146);
			updateagenttypeBean.setUpdatedUserId(vipAgentUserId1);
			updateagenttypeCall.setData(updateagenttypeBean);
			updateagenttypeCall.callService();

			Thread.sleep(2000);
			Logger.verifyEquals("200",updateagenttypeCall.getString("code"),"验证code");
            List<NotifyResModelDto> notify = getNotify(vipAgentUserId1);
            Logger.verifyEquals(false,notify.get(0).getMessage().contains(importAgentProductBean.getTitle()),"验证发送通知成功");

			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
			Logger.verifyEquals(0,agentProductPo.getInfoProgress(),"验证InfoProgress");
			Logger.verifyEquals(0,agentProductPo.getAction(),"验证InfoProgress");

			AgentProductPo agentProductPo1 = ymtProductsIWapper.selectAgentProductByProductId(agentProductId1);
			Logger.verifyEquals(0,agentProductPo1.getAction(),"验证InfoProgress");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateAgentType_02() {
		Logger.start(true,"普通渠道商修改下级代理商代理类型，修改后（代理价>下级代理商直销价）");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,sellerName,true);
			addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).setAgentPrice(300);
			addAgentProductBean.getCatalogList().get(1).getAgentPriceList().get(1).setAgentPrice(300);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(agentUserId1,agentUserName1,productId,sellerId,false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);


			updateagenttypeBean.setUserId(sellerId);
			updateagenttypeBean.setAgentTypeId(144);
			updateagenttypeBean.setUpdatedUserId(agentUserId1);
			updateagenttypeCall.setData(updateagenttypeBean);
			updateagenttypeCall.callService();

			Thread.sleep(5000);
			Logger.verifyEquals("200",updateagenttypeCall.getString("code"),"验证code");
            List<NotifyResModelDto> notify = getNotify(agentUserId1);
            Logger.verifyEquals(true,notify.get(0).getMessage().contains(importAgentProductBean.getTitle()),"验证发送通知成功");

            //同步服务会将action改成-2  时间延迟
			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
			Logger.verifyEquals(-2,agentProductPo.getInfoProgress(),"验证InfoProgress");
			Logger.verifyEquals(0,agentProductPo.getAction(),"验证action");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateAgentType_03() {
		Logger.start(true,"普通渠道商修改下级代理商代理类型，修改后该代理的一个规格无该商品规格代理权限，商品不删除，不发通知");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,sellerName,true);
			AgentPriceDto agentPriceDto = addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0);
			List<AgentPriceDto> agentPriceDtos = new ArrayList<>();
			agentPriceDtos.add(agentPriceDto);
			addAgentProductBean.getCatalogList().get(0).setAgentPriceList(agentPriceDtos);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(agentUserId1,agentUserName1,productId,sellerId,false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);


			updateagenttypeBean.setUserId(sellerId);
			updateagenttypeBean.setAgentTypeId(144);
			updateagenttypeBean.setUpdatedUserId(agentUserId1);
			updateagenttypeCall.setData(updateagenttypeBean);
			updateagenttypeCall.callService();
            Logger.verifyEquals("200",updateagenttypeCall.getString("code"),"验证code");

            Thread.sleep(5000);
            List<NotifyResModelDto> notify = getNotify(agentUserId1);
            Logger.verifyEquals(false,notify.get(0).getMessage().contains(importAgentProductBean.getTitle()),"验证发送通知成功");

            //同步服务会将action改成-2  时间延迟
			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
			Logger.verifyEquals(0,agentProductPo.getInfoProgress(),"验证InfoProgress");
			Logger.verifyEquals(0,agentProductPo.getAction(),"验证action");
			YmtProductsI ymtProductsI = ymtProductsIWapper.selectProductByProductId(agentProductId).get(0);
			Logger.verifyEquals(0,ymtProductsI.getiAction(),"验证商品表商品删除");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateAgentType_06() {
		Logger.start(true,"普通渠道商修改下级代理商代理类型，修改后该代理的所有规格无该商品规格代理权限，商品删除，不发通知");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,sellerName,true);
			AgentPriceDto agentPriceDto = addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0);
			List<AgentPriceDto> agentPriceDtos = new ArrayList<>();
			agentPriceDtos.add(agentPriceDto);
			addAgentProductBean.getCatalogList().get(0).setAgentPriceList(agentPriceDtos);
			addAgentProductBean.getCatalogList().get(1).setAgentPriceList(agentPriceDtos);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(agentUserId1,agentUserName1,productId,sellerId,false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			updateagenttypeBean.setUserId(sellerId);
			updateagenttypeBean.setAgentTypeId(144);
			updateagenttypeBean.setUpdatedUserId(agentUserId1);
			updateagenttypeCall.setData(updateagenttypeBean);
			updateagenttypeCall.callService();

			Thread.sleep(5000);
			Logger.verifyEquals("200",updateagenttypeCall.getString("code"),"验证code");
			List<NotifyResModelDto> notify = getNotify(agentUserId1);
			Logger.verifyEquals(false,notify.get(0).getMessage().contains(importAgentProductBean.getTitle()),"验证发送通知成功");

			//同步服务会将action改成-2  时间延迟
			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
			Logger.verifyEquals(0,agentProductPo.getInfoProgress(),"验证InfoProgress");
			Logger.verifyEquals(0,agentProductPo.getAction(),"验证InfoProgress");

			YmtProductsI ymtProductsI = ymtProductsIWapper.selectProductByProductId(agentProductId).get(0);
			Logger.verifyEquals(0,ymtProductsI.getiAction(),"验证商品表商品删除");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateAgentType_07() {
		Logger.start(true,"单规格商品，普通渠道商修改下级代理商代理类型，修改后该代理的其中所有规格代理价为0，商品不删除，不发通知");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,sellerName,true);
			//单规格
            addAgentProductBean.getCatalogList().remove(0);
			addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).setAgentPrice(0);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(agentUserId1,agentUserName1,productId,sellerId,false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			updateagenttypeBean.setUserId(sellerId);
			updateagenttypeBean.setAgentTypeId(144);
			updateagenttypeBean.setUpdatedUserId(agentUserId1);
			updateagenttypeCall.setData(updateagenttypeBean);
			updateagenttypeCall.callService();
            Logger.verifyEquals("200",updateagenttypeCall.getString("code"),"验证code");

            Thread.sleep(5000);
            List<NotifyResModelDto> notify = getNotify(agentUserId1);
            Logger.verifyEquals(false,notify.get(0).getMessage().contains(importAgentProductBean.getTitle()),"验证发送通知成功");

            //同步服务会将action改成-2  时间延迟
			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
			Logger.verifyEquals(0,agentProductPo.getInfoProgress(),"验证InfoProgress");
			Logger.verifyEquals(0,agentProductPo.getAction(),"验证action");
			YmtProductsI ymtProductsI = ymtProductsIWapper.selectProductByProductId(agentProductId).get(0);
			Logger.verifyEquals(0,ymtProductsI.getiAction(),"验证商品表商品删除");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}



	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateAgentType_04() {
		Logger.start(true,"多规格商品，普通渠道商修改下级代理商代理类型，修改后该代理的其中一个规格代理价为0,商品不删除,不发通知");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,sellerName,true);
			addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).setAgentPrice(0);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(agentUserId1,agentUserName1,productId,sellerId,false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			updateagenttypeBean.setUserId(sellerId);
			updateagenttypeBean.setAgentTypeId(144);
			updateagenttypeBean.setUpdatedUserId(agentUserId1);
			updateagenttypeCall.setData(updateagenttypeBean);
			updateagenttypeCall.callService();

			Thread.sleep(5000);
			Logger.verifyEquals("200",updateagenttypeCall.getString("code"),"验证code");
			//同步服务会将action改成-2  时间延迟
            List<NotifyResModelDto> notify = getNotify(agentUserId1);
            Logger.verifyEquals(false,notify.get(0).getMessage().contains(importAgentProductBean.getTitle()),"验证发送通知成功");

            AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
			Logger.verifyEquals(0,agentProductPo.getInfoProgress(),"验证InfoProgress");
			Logger.verifyEquals(0,agentProductPo.getAction(),"验证InfoProgress");
			YmtProductsI ymtProductsI = ymtProductsIWapper.selectProductByProductId(agentProductId).get(0);
			Logger.verifyEquals(0,ymtProductsI.getiAction(),"验证商品表商品删除");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateAgentType_05() {
		Logger.start(true,"渠道商修改代理类型，无正常商品修改");
		try {
			//查看后台日志
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(500008894,vipRootUserName,false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(500008895,vipAgentUserName1,productId,500008894,false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			updateagenttypeBean.setUserId(500008894);
			updateagenttypeBean.setAgentTypeId(4478);
			updateagenttypeBean.setUpdatedUserId(500008895);
			updateagenttypeCall.setData(updateagenttypeBean);
			updateagenttypeCall.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateAgentType_0501() {
		Logger.start(true,"渠道商修改代理类型，商品未设置代理价，操作成功");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,sellerName,false);
			//单规格
			addAgentProductBean.getCatalogList().remove(0);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(agentUserId1,agentUserName1,productId,sellerId,false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			updateagenttypeBean.setUserId(sellerId);
			updateagenttypeBean.setAgentTypeId(144);
			updateagenttypeBean.setUpdatedUserId(agentUserId1);
			updateagenttypeCall.setData(updateagenttypeBean);
			updateagenttypeCall.callService();
			Logger.verifyEquals("200",updateagenttypeCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateAgentType_0502() {
		Logger.start(true,"渠道商修改代理类型，商品未设置代理价，修改后（代理价>下级代理商直销价）");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,sellerName,false);
			//单规格
			addAgentProductBean.getCatalogList().remove(0);

			AgentPriceDto agentPriceDto = new AgentPriceDto();
			agentPriceDto.setAgentTypeId(144);
			agentPriceDto.setAgentPrice(300);
			addAgentProductBean.getCatalogList().get(0).setAgentPriceList(Arrays.asList(agentPriceDto));
			addAgentProductBean.setSetAgentPrice(true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(agentUserId1,agentUserName1,productId,sellerId,false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			updateagenttypeBean.setUserId(sellerId);
			updateagenttypeBean.setAgentTypeId(144);
			updateagenttypeBean.setUpdatedUserId(agentUserId1);
			updateagenttypeCall.setData(updateagenttypeBean);
			updateagenttypeCall.callService();
			Logger.verifyEquals("200",updateagenttypeCall.getString("code"),"验证code");
			Thread.sleep(2000);
			List<NotifyResModelDto> notify = getNotify(agentUserId1);
			Logger.verifyEquals(true,notify.get(0).getMessage().contains(importAgentProductBean.getTitle()),"验证发送通知成功");

			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
			Logger.verifyEquals(-2,agentProductPo.getInfoProgress(),"验证InfoProgress");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateAgentType_0503() {
		Logger.start(true,"渠道商修改代理类型，商品未设置代理价，修改后（代理价<下级代理商直销价）");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,sellerName,false);
			//单规格
			addAgentProductBean.getCatalogList().remove(0);

			AgentPriceDto agentPriceDto = new AgentPriceDto();
			agentPriceDto.setAgentTypeId(144);
			agentPriceDto.setAgentPrice(120);
			addAgentProductBean.getCatalogList().get(0).setAgentPriceList(Arrays.asList(agentPriceDto));
			addAgentProductBean.setSetAgentPrice(true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(agentUserId1,agentUserName1,productId,sellerId,false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			updateagenttypeBean.setUserId(sellerId);
			updateagenttypeBean.setAgentTypeId(144);
			updateagenttypeBean.setUpdatedUserId(agentUserId1);
			updateagenttypeCall.setData(updateagenttypeBean);
			updateagenttypeCall.callService();
			Logger.verifyEquals("200",updateagenttypeCall.getString("code"),"验证code");
			Thread.sleep(2000);
			List<NotifyResModelDto> notify = getNotify(agentUserId1);
			Logger.verifyEquals(false,notify.get(0).getMessage().contains(importAgentProductBean.getTitle()),"验证发送通知成功");

			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
			Logger.verifyEquals(0,agentProductPo.getInfoProgress(),"验证InfoProgress");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateAgentType_0504() {
		Logger.start(true,"渠道商修改代理类型，商品设置代理价，修改后无代理价（渠道商直销价>下级代理商直销价）");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,sellerName,false);
			//单规格
			addAgentProductBean.getCatalogList().remove(0);
			addAgentProductBean.getCatalogList().get(0).setDirectPrice(300d);
			AgentPriceDto agentPriceDto = new AgentPriceDto();
			agentPriceDto.setAgentTypeId(143);
			agentPriceDto.setAgentPrice(90);
			addAgentProductBean.getCatalogList().get(0).setAgentPriceList(Arrays.asList(agentPriceDto));
			addAgentProductBean.setSetAgentPrice(true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(agentUserId1,agentUserName1,productId,sellerId,false);
			importAgentProductBean.getCatalogList().get(0).setDirectPrice(200d);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			updateagenttypeBean.setUserId(sellerId);
			updateagenttypeBean.setAgentTypeId(144);
			updateagenttypeBean.setUpdatedUserId(agentUserId1);
			updateagenttypeCall.setData(updateagenttypeBean);
			updateagenttypeCall.callService();
			Logger.verifyEquals("200",updateagenttypeCall.getString("code"),"验证code");
			Thread.sleep(2000);
			List<NotifyResModelDto> notify = getNotify(agentUserId1);
			Logger.verifyEquals(true,notify.get(0).getMessage().contains(importAgentProductBean.getTitle()),"验证发送通知成功");

			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
			Logger.verifyEquals(-2,agentProductPo.getInfoProgress(),"验证InfoProgress");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateAgentType_006() {
		Logger.start(true, "代理切换成自动继承、查看商品是否会自动有");
		try {
			// 创建两个用户
			UserCreateBean usercreateBean1 = DGUserCallService.initUsercreateBean();
			int userId_channl = DGUserCallService.UserCreateCall(usercreateBean1);
			usercreateBean1 = DGUserCallService.initUsercreateBean();
			int userId_agent = DGUserCallService.UserCreateCall(usercreateBean1);
			// 设置渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			// 渠道商创建一个邀请码，出来一个自动继承的代理商、自动继承渠道商刚才的商品
			CreateCodeBean createbean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId_channl);
			createbean.setAgentModel(1);// 自动继承
			CreateCodeCall CreateCodeCall = GodmchManageCallService.createCodeCall(createbean);
			List<createmchBean> createmchList = GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl,
					userId_agent); //
			createmchList.get(0).setCode(CreateCodeCall.getCode());
			GodmchManageCallService
					.createmchCallForAgent(createmchList.toArray(new createmchBean[createmchList.size()]));

			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,
					usercreateBean1.getNickname(), true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
//			//代理商导入
//			ImportAgentProductBean initImportAgentProduct = AddAgentProductCallService.initImportAgentProduct(
//					userId_agent, usercreateBean1.getNickname(), productId, userId_channl, false);
//			String productId1 = AddAgentProductCallService.ImportAgentProduct(initImportAgentProduct);
				
			
			List<ProductListDto> getProductLists = AddAgentProductCallService.GetProductLists(userId_agent);
			System.out.println(getProductLists);
			
			Thread.sleep(5000);
			//渠道商查询
			
			updateagenttypeBean.setUserId(userId_channl);
			updateagenttypeBean.setAgentModel(2);
			updateagenttypeBean.setAgentTypeId(144);
			updateagenttypeBean.setUpdatedUserId(userId_agent);
			updateagenttypeCall.setData(updateagenttypeBean);
			updateagenttypeCall.callService();
			Logger.verifyEquals("200",updateagenttypeCall.getString("code"),"验证code");
			

			Thread.sleep(5000);
			List<ProductListDto> getProductLists1 = AddAgentProductCallService.GetProductLists(userId_agent);
			System.out.println(getProductLists1);
			

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	private void GetProductListCall(GetProductListBean initGetProductListBean) {
		// TODO 自动生成的方法存根
		
	}

	public static List<NotifyResModelDto> getNotify(int userId) throws IOException {
		GetMessageListByTimelineNewBean getmessagelistbytimelinenewBean = new GetMessageListByTimelineNewBean();
		GetMessageListByTimelineNewCall getmessagelistbytimelinenewCall = new GetMessageListByTimelineNewCall();
		getmessagelistbytimelinenewBean.setFromUserId("19000200");
		getmessagelistbytimelinenewBean.setToUserId(userId);
		getmessagelistbytimelinenewBean.setIsNew(MessageIsNew.No);
		getmessagelistbytimelinenewBean.setLongTimeline(YMTDateUtil.getDate().getTime());
		getmessagelistbytimelinenewBean.setMessageCount(20);
		getmessagelistbytimelinenewBean.setIsNotClearUnReadCount(true);
		getmessagelistbytimelinenewCall.setData(getmessagelistbytimelinenewBean);
		getmessagelistbytimelinenewCall.callService();
		List<NotifyResModelDto> notifyResModelDtos = getmessagelistbytimelinenewCall.getResults();
		return notifyResModelDtos;
	}

}